<template>
	<view class="blindBoxList">
		<!-- <header-box :title="pageTitle"></header-box> -->
		<view class="blindBoxList-box">
			<mescroll-uni ref="mescrollRef" :isBack="true" @init="mescrollInit" height="100%" :top="mescrollUni_Top" :bottom="mescrollUniBottom" :total="total" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
				<view class="blindBoxList-main">
					<view class="blindBoxList-main-item" v-for="item,index in blindList" :key="index" @click="toDetail(item)">
						<view class="blindBoxList-main-item-box">
							<view class="blindBoxList-main-item-goods">
								<image class="blindBoxList-main-item-goods-img noSaveImg" :src="item.boxImg" mode=""></image>
							</view>
							<view class="blindBoxList-main-item-info">
								<view class="blindBoxList-main-item-info-title single-line"><text>{{item.boxName}}</text></view>
								<view class="blindBoxList-main-item-info-num single-line"><text>库存数量：{{item.currentNum}}</text></view>
								<view class="blindBoxList-main-item-info-price">
									<text>￥{{item.price}}</text>
									<view class="blindBoxList-main-item-info-price-line"></view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin,MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				pageTitle:'盲盒列表',
				blindList: [],
				total:0,
				params:{
					page: 1,
					pageSize: 10
				},
				downOption:{
					auto:false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption:{
					auto:false, // 不自动加载
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量
					},
					noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					toTop:{
						offset:400,
					},
					empty:{
						tip: '~ 空空如也 ~', // 提示
						btnText: ''
					},
					elItem:{
						top:256,
						height:265,
						rowNum:2,
					}
				},
				mescrollUni_Top:0,
				mescrollUniBottom:0,
			};
		},
		mounted() {
			this.mescroll.setPageNum(1)
			this.mescroll.resetUpScroll(true)
			this.mescroll.scrollTo(0,300)
		},
		methods:{
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				// console.log(page.num)
				this.params.page = page.num
				this.getList()
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			//获取订单列表
			getList(){
				this.mescroll.lockUpScroll(true)
				this.$api.getGiftBoxList(this.params).then(res => {
					console.log(res)
					let curLen = this.blindList.length
					let totalPage
					if(res.code == 200){
						if(this.params.page == 1) this.blindList = []
						this.blindList = this.blindList.concat(res.data.records)
						curLen = this.blindList.length
						totalPage = Math.ceil(res.data.total / this.params.pageSize)
						setTimeout(() => {
							this.mescroll.endByPage(curLen, totalPage);
						},200)
						this.total = res.data.total
					}
					// console.log(this.upOption.toTop)
					// this.mescroll.endSuccess(curLen)
					setTimeout(() => {
						this.mescroll.lockUpScroll(false)
					},800)
				},err => {
					setTimeout(() => {
						this.mescroll.lockUpScroll(false)
					},800)
					this.mescroll.endErr()
				})
			},
			toDetail(item) {
				uni.navigateTo({
					url:`/pages/detailsBox/detailsBox?boxId=${item.boxId}`
				})
			}
		}
	}
</script>

<style lang="less">
	.blindBoxList{
		width: 100%;
		font:caption;
		min-height: 100vh;
		background-color: #16181D;
		display: flow-root;
		.blindBoxList-box{
			// display: flex;
			width: 100%;
		}
		.blindBoxList-main{
			width: 100%;
			padding: 0 32rpx;
			box-sizing: border-box;
			.blindBoxList-main-item{
				width: 100%;
				height: 330rpx;
				display: flex;
				flex-direction: column;
				justify-content: flex-end;
				margin-top: 32rpx;
				.blindBoxList-main-item-box{
					height: 276rpx;
					background: #262A34;
					border-radius: 40rpx;
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
				}
				.blindBoxList-main-item-goods{
					width: 332rpx;
					height: 100%;
					position: relative;
					.blindBoxList-main-item-goods-img{
						width: 300rpx;
						height: 300rpx;
						position: absolute;
						top: -54rpx;
						left: 32rpx;
						border-radius: 40rpx;
					}
				}
				.blindBoxList-main-item-info{
					width: calc(100% - 332rpx);
					padding: 32rpx 0 0 40rpx;
					box-sizing: border-box;
					.blindBoxList-main-item-info-title{
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
						font-weight: 400;
						color: #FFFFFF;
						line-height: 56rpx;
					}
					.blindBoxList-main-item-info-num{
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
						font-weight: 400;
						color: #5D5F7A;
						margin-top: 4rpx;
					}
					.blindBoxList-main-item-info-price{
						font-size: 36rpx;
						font-family: Inter-Bold, Inter;
						font-weight: bold;
						color: #A06AF9;
						text-shadow: 0px 16rpx 32rpx rgba(0, 0, 0, 0.5);
						position: relative;
						margin-top: 60rpx;
						.blindBoxList-main-item-info-price-line{
							width: 116rpx;
							height: 20rpx;
							background: #86E9A4;
							box-shadow: 0px 16rpx 32rpx 0px rgba(0, 0, 0, 0.5);
							opacity: 0.05;
							position: absolute;
							bottom: 0rpx;
							left: 0;
						}
					}
				}
			}
		}
	}
</style>
